import config from '@/config'
const { localMenuList } = config
// 初始数据
const g_initState = {
  gLoading: false, // 全局loading(layout)
  pLoading: false, // 页面loading(page)
  loading: false, // 全局 备用loading
  searching: false, // search loading
  uploading: false, // 上传 loading

  userInfo: {},

  menuList: localMenuList,
  menuSelectedKeys: [],

  dic: {},
}
// 全局数据reducer
export default (state = g_initState, action: actionType) => {
  let { type, payload } = action
  switch (type) {
    // loading
    case 'G/ON_gLoading':
      return {
        ...state,
        gLoading: true,
      }
    case 'G/OFF_gLoading':
      return {
        ...state,
        gLoading: false,
      }
    case 'G/ON_pLoading':
      return {
        ...state,
        pLoading: true,
      }
    case 'G/OFF_pLoading':
      return {
        ...state,
        pLoading: false,
      }
    case 'G/ON_loading':
      return {
        ...state,
        loading: true,
      }
    case 'G/OFF_loading':
      return {
        ...state,
        loading: false,
      }
    case 'G/ON_searching':
      return {
        ...state,
        searching: true,
      }
    case 'G/OFF_searching':
      return {
        ...state,
        searching: false,
      }
    case 'G/ON_uploading':
      return {
        ...state,
        uploading: true,
      }
    case 'G/OFF_uploading':
      return {
        ...state,
        uploading: false,
      }
    // 用户info
    case 'G/setupUserInfo':
      return {
        ...state,
        userInfo: payload,
      }
    // 菜单
    case 'G/setupMenuList':
      return {
        ...state,
        menuList: payload,
      }
    case 'G/setupMenuSelectedKeys':
      return {
        ...state,
        menuSelectedKeys: payload,
      }

    // 字典集合
    case 'G/setupDic':
      return {
        ...state,
        dic: payload,
      }

    default:
      return state
  }
}
